package cn.kgc.vue.controller;

import cn.kgc.vue.annotation.LogAnnotation;
import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Course;
import cn.kgc.vue.service.CourseService;
import cn.kgc.vue.enums.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("course")
@Api(tags = "课程模块")
public class CourseController {

    @Resource
    private CourseService courseService;

    @PostMapping("list")
    @ApiOperation("分页")
    public ResponseResult list(@RequestBody QueryCondition<Course> queryCondition) {
        return courseService.coursePage(queryCondition);
    }

    @LogAnnotation(model="课程模块",operation= OperationType.ADD)
    @RequiresPermissions(value = {"base:course:add","base:course:update"},logical = Logical.AND)
       @PostMapping("savaOrUpdateCourse")
       @ApiOperation("添加修改课程")
    public ResponseResult savaOrUpdateCourse(@RequestBody Course course) {



        return courseService.savaOrUpdateCourse(course);
    }

    @LogAnnotation(model="课程模块",operation= OperationType.DELETE)
    @RequiresPermissions("base:course:delete")
    @DeleteMapping("deleteCourse/{id}")
       @ApiOperation("删除课程")
    public ResponseResult deleteCourse(@PathVariable Integer id) {
        courseService.removeById(id);
        return ResponseResult.success().message("删除成功");
    }


















}
